﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.TransferCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.TransferHandler
{
	/// <summary>
	/// 后裔转种添加命令处理器
	/// </summary>
	public class TransferAddHandler : IRequestHandler<ProgenyTransferAddCommand, Results<int>>
	{

		private readonly IProgenyTransferService service;
        private readonly IMapper mapper;

        public TransferAddHandler(IProgenyTransferService service, IMapper mapper)
		{
			this.service = service;
			this.mapper = mapper;
        }

		/// <summary>
		/// 后裔转种添加命令处理器
		/// </summary>
		/// <param name="request"></param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>


		public async Task<Results<int>> Handle(ProgenyTransferAddCommand request, CancellationToken cancellationToken)
		{
			var entity= mapper.Map<List<ProgenyTransfer>>(request.TransferInputList);
			var result =await service.AddProgenyTransfer(entity);
	          	return   Results<int>.DataResult(result);

		    // throw new NotImplementedException();
		}
	}

}
